package longrise.phone.com.bjjt_henan.myaccident;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.FormParameter;
import com.longrise.android.LFView;

import longrise.phone.com.bjjt_henan.R;
import longrise.phone.com.bjjt_henan.Utils.CommontUtils;

/**
 * 定损信息界面
 */
public class LossInfoView extends LFView {

    private Context mContext;

    private LinearLayout mView;

    private EntityBean[] baseBean;

    public LossInfoView(Context context, EntityBean[] bean) {
        super(context);
        this.mContext = context;
        this.baseBean = bean;
    }

    @Override
    public FormParameter getFormParameter() {
        FormParameter form = new FormParameter();
        form.setShowtitle(false);
        return form;
    }

    @Override
    public View getView() {
        return mView;
    }

    @Override
    public void init() {
        if (null == mContext) {
            return;
        }
        mView = new LinearLayout(mContext);
        mView.setOrientation(LinearLayout.VERTICAL);
        mView.setBackgroundColor(mContext.getResources().getColor(R.color.backgroudColor));
        //标题栏
        View titleView = LayoutInflater.from(mContext).inflate(R.layout.common_titlehn_layout, null);
        TextView titleTV = (TextView) titleView.findViewById(R.id.tv_title);
        titleTV.setText(R.string.loss_info);
        titleView.findViewById(R.id.hn_btn_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                closeForm();
                OnDestroy();
            }
        });
        LayoutParams titleParams = new LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        mView.addView(titleView, titleParams);
        //定损信息
        for (int i = 0; i < baseBean.length; i++) {
            View view = getInfoView(baseBean[i]);
            LayoutParams otherParams = new LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            mView.addView(view, otherParams);
        }
    }

    private View getInfoView(EntityBean bean) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.view_lossinfo, null);
        //信息
        TextView infoTV = (TextView) view.findViewById(R.id.linfo_tv_title);
        String ownother = bean.getString("ownother");
        if (TextUtils.equals("0", ownother)) {
            infoTV.setText(R.string.self_loss);
        } else if (TextUtils.equals("1", ownother)) {
            infoTV.setText(R.string.other_loss);
        }
        //金额
        TextView moneyTV = (TextView) view.findViewById(R.id.linfo_tv_num);
        moneyTV.setText(bean.getString("feepaymoney") + "元");
        //责任
        TextView stateTV = (TextView) view.findViewById(R.id.linfo_tv_state);
        stateTV.setText(CommontUtils.getDutyStr(bean.getString("dutytype")));
        //驾驶人
        TextView nameTV = (TextView) view.findViewById(R.id.linfo_tv_name);
        nameTV.setText(bean.getString("carownname"));
        //车牌
        TextView carnumTV = (TextView) view.findViewById(R.id.linfo_tv_carnum);
        carnumTV.setText(bean.getString("casecarno"));
        //电话
        TextView phoneTV = (TextView) view.findViewById(R.id.linfo_tv_phonenum);
        phoneTV.setText(bean.getString("carownphone"));
        return view;
    }

    @Override
    public void refresh() {

    }

    @Override
    public void refreshByTime() {

    }

    @Override
    public void OnDestroy() {
        super.OnDestroy();
        mView = null;
        baseBean = null;
    }
}
